package utils;

import models.User;
import play.mvc.Scope.Session;

public class SessionUtils {
	
	public static final String userKey = "userId";

	Session session = Session.current();

	public static void saveUserId(String userId){
        Session session = Session.current();
		session.put(userKey, userId);
	}
	
	public static String getUserId(){
        Session session = Session.current();
		return session.get(userKey);
	}
	
	public static void clear(){
        Session session = Session.current();
        session.clear();
	}
	
	public static User getLoginUser(){
		if(SessionUtils.getUserId() != null){
			return User.findById(SessionUtils.getUserId());
		}
		return null;
	}
    public static int getEmail(){
        if (SessionUtils.getUserId() != null) {
            User user = User.findById(SessionUtils.getUserId());
            return user.hasEmail;
        }
        else{
            return 0;
        }
    }

	
}
